package classifier;
import edu.stanford.nlp.classify.ColumnDataClassifier;
import entity.ClassifierResult;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by sunjia on 2018/1/10.
 */
public class MaxEnt {

    String path_prop; //配置文件地址
    String path_model; //model地址
    ColumnDataClassifier cdc;


    public MaxEnt(String path_prop, String path_model) {
        this.path_prop = path_prop;
        this.path_model = path_model;
        cdc = new ColumnDataClassifier(path_prop, path_model);
    }

    //训练数据
    public void maxentTrain(String trainFile, String serializeTo){
        try {
            cdc.trainClassifier(trainFile, serializeTo);
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("训练失败");
        }

    }

//    测试line
    public List<ClassifierResult> maxentPredict(String line) {

        List<ClassifierResult> classifierResults = new ArrayList<>();
        try {
            classifierResults = cdc.predict(line);

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("预测失败");
        }
        return classifierResults;
    }

    //    测试line for Tu
    public List<ClassifierResult> maxentPredict1(String line) {

        List<ClassifierResult> classifierResults = new ArrayList<>();
        try {
            classifierResults = cdc.predict1(line);

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("预测失败");
        }
        return classifierResults;
    }


}
